package security.core.filter.handler.impl;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import security.core.filter.handler.LoginResultHandler;
import security.debug.RBACLogger;

public class RBACLoginResultHandler implements LoginResultHandler {

	@Override
	public void onLoginResult(ServletRequest request,
			ServletResponse response, Boolean success, String redirectURL) throws IOException,
			ServletException {
		// TODO Auto-generated method stub
		if (RBACLogger.debug()) {
			RBACLogger.log("RBACLoginResultHandler#onLoginResult is called!");
		}
		if (success) {
			if (RBACLogger.debug()) {
				RBACLogger.log("RBACLoginResultHandler#onLoginResult login success!");
			}
			((HttpServletResponse)response).sendRedirect(redirectURL);
		} else {
			if (RBACLogger.debug()) {
				RBACLogger.log("RBACLoginResultHandler#onLoginResult login fail!");
			}
			// login fail redirect to login page
			((HttpServletResponse)response).sendRedirect(redirectURL);
		}
	}

}
